const DoublyLinkedList = require("../template.js") // 链表实现的导出路径

/** 1. 基础功能测试 */
function testBasic() {
  const link = new DoublyLinkedList()

  // 测试空链表
  console.log("0.1 空链表长度:", link.size === 0)
  console.log("0.2 空链表检查:", link.isEmpty() === true)

  // 测试追加
  link.append(1).append(2)
  console.log("0.3 尾部追加:", link.tail.value === 2)

  // 测试头部添加
  link.prepend(0)
  console.log("0.4 头部添加:", link.head.value === 0)

  // 测试长度
  console.log("0.5 长度检查:", link.size === 3)
  
  // this上下文测试
  const linkObj = {
    multiplier: 2,
    list: new DoublyLinkedList(),
    process: function(items) {
      items.forEach(item => this.list.append(item * this.multiplier))
      return this.list.size
    }
  }
  console.log("0.6 this上下文测试:", linkObj.process([1, 2, 3]) === 3)
  
  // 复杂对象this绑定测试
  const complexObj = {
    prefix: "node_",
    list: new DoublyLinkedList(),
    addWithPrefix: function(values) {
      values.forEach(value => {
        this.list.append(this.prefix + value)
      })
      return this.list.size
    }
  }
  console.log("0.7 复杂对象this绑定:", complexObj.addWithPrefix([1, 2]) === 2)
  
  console.log("--------------------")
}

testBasic()
